<template>
  <div class="login">
    <div class="content">
       <div class="cont_img">
         <img src="../../assets/login/img2.png" />
       </div>
       <div class="verify_box">
         <div class="title"><span class="font_c">华圆</span>EMS管理系统</div>
        <el-form
          :model="loginForm"
          :rules="rules"
          ref="loginForm"
          class="demo-dynamic"
          size="medium"
        >
          <el-form-item prop="userName">
            <el-input v-model="loginForm.userName" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item  prop="password">
            <el-input v-model="loginForm.password" placeholder="请输入密码"></el-input>
          </el-form-item>
          <div class="tips">您在本页面操作的登陆或注册行为，均代表您已阅读并同意本公司的<span class="tips_c">用户注册协议</span>和<span class="tips_c">隐私政策</span></div>
          <el-form-item>
            <el-button class="login_btn" type="primary" @click="onSubmit">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
   
  </div>
</template>
<script>
import { loginApi } from '@/api'

export default {
  name: "",
  components: {},
  data() {
    return {
      loginForm: {
        userName:'',
        password:''
      },
      rules:{
        userName: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
          ],
        password: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ],
      }
    };
  },
  created() {},
  methods: {

    //登录
    onSubmit() {
      this.$refs.loginForm.validate(async(valid) => {
         if (valid) {
            let res = await loginApi({
              userName:this.loginForm.userName,
              password:this.loginForm.password
            })
            if(res.code=='200' && res.msg =='成功'){
              sessionStorage.setItem('token',res.data)
              sessionStorage.setItem('useId',res.userInfo.useId)
              sessionStorage.setItem('depart',res.userInfo.depart)
              sessionStorage.setItem('auth',res.userInfo.auth)
               this.$router.replace({
                  path: "/home"
                });
            }else{
              this.$message({
                message: '登录失败',
                type: 'warning'
              });
              console.log("登录失败")
            }
          } else {
            console.log('error submit!!');
            return false;
          }
      })
     
    }
  }
};
</script>
<style lang="less" scoped>
.login {
  width: 100vw;
  height: 100vh;
  background: url('../../assets/login/back.png') no-repeat;
  background-size: 100% 100%;
  display: flex;
  justify-content: center;
  align-items: center;

  .content{
    width: 8rem;
    height: 4rem;
    background: #fff;
    border-radius: .53rem;
    box-shadow: 1px 1px 25px #011133;
    display: flex;
    .cont_img{
      width: 3.52rem;
      img{
        width: 100%;
      }
    }
    .verify_box {
    width: 3rem;
    margin: 15px auto;
    .title{
      font-size: .25rem;
      font-weight: 700;
      color: rgb(12, 72, 100);
      text-align: center;
      margin: 30px;
      .font_c {
        color: rgb(241, 163, 68);
      }
    }
    
    .el-button {
        margin-left: 10px;
        background: #041e55;
        border:0;
      }
    .login_btn{
      display: block;
      margin: 10px auto;
      border-radius:20px;
      width: 3rem;
    }
    .tips{
      font-size: 10px;
      color: #999999;
      position: relative;
      top:-10px;

      .tips_c{
        color:#D19EFF;
      }
    }
  }
  }

}
</style>
<style lang="less">
.verify_box {
  .el-input__inner{
        border-radius: 20px;
    }
}
</style>
